package com.shanzmoo.admin.web.third;

import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.base.bean.SResponse;
import com.shanzmoo.base.constant.Constant;
import com.shanzmoo.core.cache.CurrentUserCache;
import com.shanzmoo.db.third.entity.bo.PlatformOrderAddLogisticsBO;
import com.shanzmoo.db.third.entity.bo.PlatformOrderSellerRemarkBO;
import com.shanzmoo.db.third.entity.query.PlatformlOrderPageQuery;
import com.shanzmoo.db.third.entity.vo.PlatformOrderPageVO;
import com.shanzmoo.db.third.service.IPlatformOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * 第三方平台订单
 *
 * @author Gzhao 2021/1/7
 */
@Slf4j
@RestController
@Api(tags = "第三方平台-订单管理")
@RequestMapping("/third/platform/order")
public class PlatformOrderController {

    @Autowired
    private IPlatformOrderService platformOrderService;

    @ApiOperation(value = "分页列表")
    @PostMapping("/pageList")
    public SHttpResponse<PageRespBase<PlatformOrderPageVO>> pageList(@Valid @RequestBody PlatformlOrderPageQuery query) {
        SResponse<PageRespBase<PlatformOrderPageVO>> re = platformOrderService.getPageList(query);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "发货")
    @PostMapping("/addLogistics")
    public SHttpResponse<Boolean> addLogistics(@Valid @RequestBody PlatformOrderAddLogisticsBO logistics) {
        SResponse<Boolean> re = platformOrderService.addLogistics(logistics, CurrentUserCache.getUserId());
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "添加卖家备注")
    @PostMapping("/addSellerRemark")
    public SHttpResponse<Boolean> addSellerRemark(@Valid @RequestBody PlatformOrderSellerRemarkBO sellerRemark) {
        SResponse<Boolean> re = platformOrderService.addSellerRemark(sellerRemark, CurrentUserCache.getUserId());
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "批量导入商品")
    @PostMapping("/import")
    public SHttpResponse<Boolean> importByExcel(@RequestParam("file") MultipartFile file) {
        if (file == null || file.isEmpty()) {
            log.error("文件上传失败，上传的文件为空！");
            return SHttpResponse.fail(Constant.ERRCODE_PARAM, "上传文件不能为空");
        }

        SResponse<Boolean> re = platformOrderService.importByExcel(file);
        return SHttpResponse.transform(re);
    }
}
